const codeidea = require("../models/codeidea")
const user = require("../models/userDetail")

var express = require('express');
var router = express.Router();

const formidable = require('formidable');

//返回图片
router.post('/', (req, res, next) => {
    var form = new formidable.IncomingForm();
    form.parse(req, async function (err, fields, files) {
        if (err) {
            res.json({ 'state': false })
        } else {
            let student = await user.find({
                flags: {
                    $all: fields.flags
                }
            }, {
              UUID: 1
            })
            // console.log(student)
            let stu_list = []
            student.forEach(item => {
              stu_list.push(item.UUID)
            })
            codeidea.find({
                UUID: {
                    $in: stu_list
                },
                pointId: fields.pointId,
                demoId: fields.demoId
            },{
              process: 1
            }, (error, doc) => {
              // console.log(doc)
              // console.log(doc)
                if (error) {
                    res.json({ 'state': false, 'msg': error });
                } else {
                    res.json({ 'state': true, 'msg': doc });
                }
            })

        }

    });

});

module.exports = router;